from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
from sqlalchemy import Integer, String
from ..database.db import Base  # 假设这是你定义的基类

class Grades(Base):
    __tablename__ = 'grades'

    # 定义 id 列，类型为 Integer，为主键且不为空，并且自动递增
    id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True, nullable=False)

    # 定义 name 列，类型为 String(255)，且不为空
    name: Mapped[str] = mapped_column(String(255), nullable=False)

    def as_dict(self):
        return {c.name: getattr(self, c.name) for c in self.__table__.columns}
